using Dialog.Data;
using System.Collections.Generic;
using UnityEngine;

public interface IDialogueCommand
{
    void Execute(DialogueRuntime runtime);
}

namespace Dialog.Data
{
    public class DialogueScript
    {
        public string background;
        public string bgm;
        public string title;

        public Dictionary<int, DialogueBlock> dialogueBlocks = new();
        public List<ChoiceItem> choices = new();
    }

    public class DialogueBlock
    {
        public int id;
        public List<IDialogueCommand> commands = new();
    }

    public class ChoiceItem
    {
        public string text;
        public int targetBlock;
    }


    public class DialogueRuntime
    {
        public DialogueScript script;
        public DialogScenePanel ui;

        private int currentBlockId;
        private int currentCommandIndex;

        public void StartDialogue(int blockId)
        {
            currentBlockId = blockId;
            currentCommandIndex = 0;
            Continue();
        }

        public void Continue()
        {
            var block = script.dialogueBlocks[currentBlockId];

            if (currentCommandIndex >= block.commands.Count)
                return;

            var cmd = block.commands[currentCommandIndex++];
            cmd.Execute(this);
        }

        public void EndDialogue()
        {
            Debug.Log("Dialogue Finished");
        }
    }

}
